import time

class System:
    def __init__(self):
        self.state = "Idle"  # 初始状态
        self.password = "1234"  # 假设正确的密码
        self.entered_password = ""
        self.failed_attempts = 0
        self.lock_time = 0  # 锁定时间

    def start(self):
        """启动系统"""
        self.state = "Idle"

    def enter_password(self, ch):
        """输入密码字符"""
        if self.state == "Idle" or self.state == "EnteringPassword" or self.state == "WrongPassword":
            self.entered_password += ch
            print(f"Entered password so far: {self.entered_password}")
            self.state = "EnteringPassword"  # 输入过程中，状态应为EnteringPassword

            if len(self.entered_password) == 4:
                self.verify_password()

    def verify_password(self):
        """验证密码"""
        if self.entered_password == self.password:
            self.state = "FunctionSelection"
            print("Password correct. Moving to FunctionSelection.")
        else:
            self.failed_attempts += 1
            if self.failed_attempts >= 3:
                self.state = "LockPanel"
                print("Too many failed attempts. Locked for 120 seconds.")
                self.lock_panel()
            else:
                self.state = "WrongPassword"
                self.entered_password = ''

                print(f"Wrong password. Attempt {self.failed_attempts}/3.")

    def lock_panel(self):
        """模拟锁定面板，并等待解锁"""
        self.state = "LockPanel"
        print("Locking panel...")
        # 在这里模拟锁定时间，比如设置为3秒（测试用）
        time.sleep(3)  
        print("Lock panel time passed. Unlocking now.")
        self.state = "Idle"  # 解锁后恢复为Idle

    def get_state(self):
        """获取当前系统状态"""
        return self.state

